package cn.hpclub.server.ext.jfinal.test;

import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;

import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.wall.WallFilter;
import com.jfinal.config.JFinalConfig;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.druid.DruidPlugin;

import cn.hpclub.server.cfg.JFWebConfig;
import cn.hpclub.server.model.Admin;

public class JFinalModelCase{
    
    protected static DruidPlugin druidPlugin;
    protected static ActiveRecordPlugin activeRecord;
    
    /**
     * @throws java.lang.Exception
     */
    @BeforeTest
    public static void setUpBeforeClass() throws Exception {
    	
    	JFinalConfig jc = new JFWebConfig();
    	jc.loadPropertyFile("jdbc.properties");
        druidPlugin=new DruidPlugin(jc.getProperty("jdbcUrl"), 
                                    jc.getProperty("user"), jc.getProperty("password"), jc.getProperty("driverClass"));
		druidPlugin.addFilter(new StatFilter());
		
		WallFilter wall = new WallFilter();
		wall.setDbType(jc.getProperty("db.type"));
		druidPlugin.addFilter(wall);
         
        activeRecord = new ActiveRecordPlugin(druidPlugin);
        activeRecord.setDialect(new MysqlDialect());
        
        activeRecord.addMapping("sys_user", Admin.class);
        
        druidPlugin.start(); 
        activeRecord.start();
    }
 
    /**
     * @throws java.lang.Exception
     */
    @AfterTest
    public void tearDown() throws Exception {
        activeRecord.stop();
        druidPlugin.stop();
    }
 
}
